package com.etocrm.saas.lib.base.db.base;

import com.baomidou.mybatisplus.annotation.*;
import com.etocrm.saas.lib.base.common.enums.DeleteFlagEnum;
import com.etocrm.saas.lib.base.common.obj.BaseO;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * 基类实体
 * <p>
 * 所有的entity 都继承该类
 **/
@Setter
@Getter
public class BaseEntity extends BaseO implements IEntity {

    /**
     * 主键id
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    // 创建人id
    @TableField(fill = FieldFill.INSERT)
    private Long creatorId;

    // 更新人id
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updaterId;

    // 创建时间
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    // 修改时间
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    // 逻辑删除
    // 
    @TableLogic
    private DeleteFlagEnum deleteFlag = DeleteFlagEnum.NOT_DELETED;


    public void defaultInit() {
        this.createTime = new Date();
        this.deleteFlag = DeleteFlagEnum.NOT_DELETED;
    }

    public void defaultInit(Long creatorId) {
        defaultInit();
        this.creatorId = creatorId;
    }


}
